﻿Imports System.Collections
Imports System.Net.Sockets
Imports System.Net

Public Class ISCHandler

    Public workSocket As Socket = Nothing
    Public cluster As Cluster
    Public Const BufferSize As Integer = 1024
    Public Const HeaderLen As Integer = 5
    Private buf(BufferSize) As Byte
    Private bytesRead As Integer = 0

    Public Sub New(ByVal socket As Socket)
        workSocket = socket
    End Sub

    Public Function handle() As Boolean
        Try
            bytesRead = workSocket.Receive(buf, 0, BufferSize, SocketFlags.None)
            If (bytesRead = 0) Then
                Return False
            End If
            Dim dataLength As Integer = buf(1)
            Dim ISCph As New ISCPacketHandler(Me)
            ISCph.handlePacket(buf, HeaderLen, dataLength)
            Return True
        Catch ex As SocketException
        Catch ex As Exception
            log.log(LogType.MSG_DEBUG, "Exception at ISCHandler.handle(): ")
            Console.WriteLine(ex)
            Return False
        End Try
    End Function

End Class